﻿

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using MySql.Data.MySqlClient;

public class DAL_tbl_qc_siconide_leo_carbon_oxygen
{
    public DAL_tbl_qc_siconide_leo_carbon_oxygen()
    {

    }



    public List<tbl_qc_siconide_leo_carbon_oxygen> select(int ID)
    {
        List<tbl_qc_siconide_leo_carbon_oxygen> list = new List<tbl_qc_siconide_leo_carbon_oxygen>();
        MySqlCommand cmd = new MySqlCommand();
        cmd.CommandText = "Select ID,PO_Number,DRUM_NUMBER,Carbon,Oxygen,Remark,IS_ACTIVE,CREATED_BY,CREATED_DATE,UPDATED_BY,UPDATED_DATE from tbl_qc_siconide_leo_carbon_oxygen where ID=@ID";
        cmd.Parameters.AddWithValue("@ID", ID);
        DataTable dt = DBUtil.ExecuteDataTable(cmd);
        foreach (DataRow dr in dt.Rows)
        {
            list.Add(new tbl_qc_siconide_leo_carbon_oxygen()
            {
                ID = Convert.ToInt32(dr["ID"]),
                PO_Number = dr["PO_Number"].ToString(),
                DRUM_NUMBER = dr["DRUM_NUMBER"].ToString(),
                Carbon = dr["Carbon"].ToString(),
                Oxygen = dr["Oxygen"].ToString(),
                Remark = dr["Remark"].ToString(),
                IS_ACTIVE = Convert.ToBoolean(dr["IS_ACTIVE"]),
                CREATED_BY = dr["CREATED_BY"].ToString(),
                CREATED_DATE = dr["CREATED_DATE"].toDateTimeWithoutError(),
                UPDATED_BY = dr["UPDATED_BY"].ToString(),
                UPDATED_DATE = dr["UPDATED_DATE"].toDateTimeWithoutError()
            });
        }

        return list;
    }



    public List<tbl_qc_siconide_leo_carbon_oxygen> selectAll()
    {
        List<tbl_qc_siconide_leo_carbon_oxygen> list = new List<tbl_qc_siconide_leo_carbon_oxygen>();
        MySqlCommand cmd = new MySqlCommand();
        cmd.CommandText = "Select ID,PO_Number,DRUM_NUMBER,Carbon,Oxygen,Remark,IS_ACTIVE,CREATED_BY,CREATED_DATE,UPDATED_BY,UPDATED_DATE from tbl_qc_siconide_leo_carbon_oxygen Order By ID";

        DataTable dt = DBUtil.ExecuteDataTable(cmd);
        foreach (DataRow dr in dt.Rows)
        {
            list.Add(new tbl_qc_siconide_leo_carbon_oxygen()
            {
                ID = Convert.ToInt32(dr["ID"]),
                PO_Number = dr["PO_Number"].ToString(),
                DRUM_NUMBER = dr["DRUM_NUMBER"].ToString(),
                Carbon = dr["Carbon"].ToString(),
                Oxygen = dr["Oxygen"].ToString(),
                Remark = dr["Remark"].ToString(),
                IS_ACTIVE = Convert.ToBoolean(dr["IS_ACTIVE"]),
                CREATED_BY = dr["CREATED_BY"].ToString(),
                CREATED_DATE = dr["CREATED_DATE"].toDateTimeWithoutError(),
                UPDATED_BY = dr["UPDATED_BY"].ToString(),
                UPDATED_DATE = dr["UPDATED_DATE"].toDateTimeWithoutError()
            });
        }

        return list;
    }

    public DataTable selectAllForGrid()
    {
        MySqlCommand cmd = new MySqlCommand();
        cmd.CommandText = @"Select ID,PO_Number,DRUM_NUMBER,Carbon,Oxygen,Remark,CASE WHEN IS_ACTIVE =1 THEN 'True' ELSE 'False' END as 'IS_ACTIVE',CREATED_BY,CREATED_DATE as CREATED_DATE,UPDATED_BY,UPDATED_DATE as UPDATED_DATE from tbl_qc_siconide_leo_carbon_oxygen Order By ID desc";

        DataTable dt = DBUtil.ExecuteDataTable(cmd);
        return dt;
    }

    public int insert(String PO_Number, String DRUM_NUMBER, String Carbon, String Oxygen, String Remark, String CREATED_BY, DateTime CREATED_DATE)
    {
        int i = 0;
        string sql = @"Insert into tbl_qc_siconide_leo_carbon_oxygen(PO_Number, DRUM_NUMBER, Carbon, Oxygen, Remark, CREATED_BY, CREATED_DATE)
                        values(@PO_Number, @DRUM_NUMBER, @Carbon, @Oxygen, @Remark, @CREATED_BY, @CREATED_DATE)";

        MySqlCommand cmd = new MySqlCommand(sql);

        cmd.Parameters.AddWithValue("@PO_Number", PO_Number);
        cmd.Parameters.AddWithValue("@DRUM_NUMBER", DRUM_NUMBER);
        cmd.Parameters.AddWithValue("@Carbon", Carbon);
        cmd.Parameters.AddWithValue("@Oxygen", Oxygen);
        cmd.Parameters.AddWithValue("@Remark", Remark);
        cmd.Parameters.AddWithValue("@CREATED_BY", CREATED_BY);
        cmd.Parameters.AddWithValue("@CREATED_DATE", CREATED_DATE);

        i = DBUtil.ExecuteNonQuery(cmd);
        return i;
    }



    public int update(int ID, String PO_Number, String DRUM_NUMBER, String Carbon, String Oxygen, String Remark, String UPDATED_BY, DateTime UPDATED_DATE)
    {
        int i = 0;
        string sql = @"Update tbl_qc_siconide_leo_carbon_oxygen SET PO_Number=@PO_Number, DRUM_NUMBER=@DRUM_NUMBER, Carbon=@Carbon, Oxygen=@Oxygen, Remark=@Remark, UPDATED_BY=@UPDATED_BY, UPDATED_DATE=@UPDATED_DATE WHERE ID=@ID";

        MySqlCommand cmd = new MySqlCommand(sql);

        cmd.Parameters.AddWithValue("@ID", ID);
        cmd.Parameters.AddWithValue("@PO_Number", PO_Number);
        cmd.Parameters.AddWithValue("@DRUM_NUMBER", DRUM_NUMBER);
        cmd.Parameters.AddWithValue("@Carbon", Carbon);
        cmd.Parameters.AddWithValue("@Oxygen", Oxygen);
        cmd.Parameters.AddWithValue("@Remark", Remark);
        cmd.Parameters.AddWithValue("@UPDATED_BY", UPDATED_BY);
        cmd.Parameters.AddWithValue("@UPDATED_DATE", UPDATED_DATE);

        i = DBUtil.ExecuteNonQuery(cmd);
        return i;
    }



    public int delete(int ID)
    {
        int i = 0;
        string sql = "Delete FROM tbl_qc_siconide_leo_carbon_oxygen WHERE ID=@ID";

        MySqlCommand cmd = new MySqlCommand(sql);

        cmd.Parameters.AddWithValue("@ID", ID);

        i = DBUtil.ExecuteNonQuery(cmd);
        return i;
    }



}